import com.troyworks.particleengine.Particle;
import com.troyworks.framework.ui.layout.Bounds2;
import flash.geom.Rectangle;
/**
 * @author Troy Gardner
 */
class com.troyworks.particleengine.Ch06_04 extends MovieClip {
	var p : Particle;
	var tp : Particle;
	
	var v:Particle;
	var easing : Number = .1;
	var fl : Number = 250;
	var vpX : Number = _width/2;
	var vpY : Number = _height/2;
	var ball : MovieClip;
	var bounds:Rectangle;
	
	public function Ch06_04() {
		trace("Ch06_04");
		p  = new Particle();
		tp  = new Particle();
		v = new Particle();		
	}
	public function onLoad() : Void{
		trace("onLoad");
		bounds = new Rectangle();
		bounds.top = 0;
		bounds.left = 0;
		bounds.bottom =_height;
		bounds.right = _width;
		

		p.x = bounds.left + bounds.width/2;
		p.y =bounds.top + bounds.height/2;
		
		ball._x = p.x; 
		ball._y = p.y;
		
		v.x = Math.random() * 10 -5;
		v.y = Math.random() * 10 -5;
		
	}
	function onEnterFrame() : Void {
		trace("onEnterFrame()" + util.Trace.me(p, "p1"));
		p.x +=v.x;
		p.y +=v.y;
				trace("onEnterFrame()" + util.Trace.me(p, "p2"));
		
		var b:Bounds2 = new Bounds2(ball.getBounds(this));
		///////// check x ///////////////
		if(b.xMax > bounds.right){
			trace("hit R wall");
			p.x = bounds.right - b.width;
			v.x = Math.abs(v.x)*-1;
		}else if(b.xMin < bounds.left){
			trace("hit L wall");
			p.x = bounds.left + 1;// + b.width + 1;
			v.x = Math.abs(v.x);
		}
		////////// check y ////////////////
		if(b.yMax > bounds.bottom){
			p.y = bounds.bottom- b.height;
			v.y= Math.abs(v.x)*-1;
		}else if(b.yMin < bounds.top){
			p.y = bounds.top +1 ;//+ b.height;
			v.y= Math.abs(v.x);
		}
		///// update the clip /////////
		ball._x = p.x;
		ball._y = p.y;
		
	}
	
}